package com.onlinevideo.service.impl;

import com.onlinevideo.dao.MessageDao;
import com.onlinevideo.dao.impl.MessageDaoImpl;
import com.onlinevideo.entity.Message;
import com.onlinevideo.service.MessageService;

import java.util.ArrayList;
import java.util.List;

public class MessageServiceImpl implements MessageService {

    private MessageDao messageDao = new MessageDaoImpl();

    @Override
    public int insert(Message message) {
        return messageDao.insert(message);
    }

    @Override
    public int delete(Long id) {
        return messageDao.delete(id);
    }

    @Override
    public int deleteByUserRead(Long userId) {
        return messageDao.deleteByUserRead(userId);
    }

    @Override
    public int update(Message message) {
        return messageDao.update(message);
    }

    @Override
    public Message queryById(Long id) {
        return messageDao.queryById(id);
    }

    @Override
    public List<Message> queryAll() {
        return messageDao.queryAll();
    }

    @Override
    public List<Message> queryByUserId(Long userId, Integer haveRead) {
        List<Message> messages = messageDao.queryByUserId(userId, haveRead);
        if (messages == null) {
            messages = new ArrayList<>();
        }
        return messages;
    }
}
